﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.IO;
using SyCODE.Component;

namespace SyCODE.Blog.Updater
{
    /// <summary>
    /// BLOG信息更新的抽象借口
    /// </summary>
    public abstract class Information : IDisposable
    {
        /// <summary>
        /// 个人主页文档
        /// </summary>
        protected XmlDocument UserDocument = new XmlDocument();
        /// <summary>
        /// BLOG帐号
        /// </summary>
        protected string Bloger;
        private string userPath;

        /// <summary>
        /// 更新程序的构造函数
        /// </summary>
        /// <param name="bloger">blog帐号</param>
        public Information(string bloger)
        {
            //
            // TODO: 在此处添加构造函数逻辑
            //
            Bloger = bloger;
            userPath = Path.Combine(AppPath.GetUserPhysicalPath(bloger), "main.xml");
            UserDocument.Load(userPath);
        }

        /// <summary>
        /// 保存并关闭文档
        /// </summary>
        protected virtual void Close()
        {
            UserDocument.Save(userPath);
        }

        #region IDisposable 成员

        ~Information()
        {
            Dispose(false);
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }

        protected void Dispose(bool disposing)
        {
            if (disposing)
            {
                // 释放 托管资源
                this.Close();
            }
        }

        #endregion
    }
}